package buildingsWithAnOceanView_1762;


import java.util.Map;
import java.util.Stack;

//https://leetcode.cn/problems/buildings-with-an-ocean-view/
public class Solution {
    public int[] findBuildings(int[] heights) {
        Stack<Integer> stack = new Stack<>();

        int max = Integer.MIN_VALUE;
        for (int i = heights.length - 1; i >= 0; i--) {
            if (heights[i] > max) {
                stack.add(i);
                max = heights[i];
            }
        }
        int i = 0;
        int[] target = new int[stack.size()];
        while (!stack.isEmpty()) {
            target[i++] = stack.pop();
        }
        return target;
    }
}